
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title id="divTitle"> 批量添加用户信息 </title>
    <link rel="stylesheet" type="text/css" href="/css/style.css" />
    <style type="text/css">
        /*字体风格*/
        *, body {
            margin: 0px;
            font-family: '微软雅黑',serif;
        }
        /*超链接风格*/
        a:link{
            color:red;
        }
        a:visited{
            color:#008000;
        }
        a:active{
            color:cadetblue;
        }
        a:hover{
            color: #a71d5d;
        }
    </style>
    <script src="/js/generic.js"></script>

    <script type="text/javascript" src="/js/EasyUI/jquery.min.js"></script>
    <script type="text/javascript" src="/js/EasyUI/jquery.ui.widget.js"></script>
    <script type="text/javascript" src="/js/EasyUI/jquery.iframe-transport.js"></script>
    <script type="text/javascript" src="/js/EasyUI/jquery.fileupload.js"></script>
    <script type="text/javascript" src="/js/EasyUI/jquery.fileupload-process.js"></script>
    <script type="text/javascript" src="/js/EasyUI/jquery.fileupload-validate.js"></script>
    <script type="text/javascript" src="/js/EasyUI/jquery.fileupload-ui.js"></script>


</head>

<body>
<form id="filePost" method="post" enctype="multipart/form-data" onsubmit="return false;">
    <table class="maintable">
        <tr>
            <td class="rightmaintd" valign="top">
<!--                返回的超链接-->
                <div style="width:920px;margin:10px auto;"> <a href="/user">&lt;  返回</a> </div>
<!--                上传文件-->
                <div style="margin-left:300px;margin-top:20px">
                    <span>上传文件：&nbsp;&nbsp;</span>
                    <input id="fileUpload" type="file" name="myxxFile" accept=".xls, .xlsx"/>
                    <a target="_blank" data-icon="arrow-down" class="btn btn-green" href="/batchUpload/user.xlsx">下载模板</a>
                </div>
<!--                提交按钮-->
                <div style="margin-left:300px;margin-top:20px">
                    <input type="button" value="提&nbsp;&nbsp;交" class="denglubtn1" onclick="save();">
                </div>
                <div id="progress" style="margin-left:300px;margin-top:20px">
                    <div class="progressbar" style="width:0%"></div>
                </div>
                <br />
                <table border="1" id="tab1" style="margin-left:300px"></table>
                <table class="logintable" cellpadding="8" style="margin-top:20px;"></table>
            </td>
        </tr>
    </table>
</form>
</body>
<script type="text/javascript">
    // 功能实现和与用户交互
    function save() {
        const fileInput = document.getElementById('fileUpload');
        const file = fileInput.files[0];
        if (!file) {
            alert('请先上传文件');
            return;
        }
        const formData = new FormData();
        formData.append('file', file);
        // 文件路径
        fetch('/user/batch/', {
            method: 'POST',
            body: formData
        })
            // 效果可视化
            .then(response => response.json())
            .then(data => {
                alert(data.message);
            })
            .catch(error => {
                console.error('Error:', error);
                alert('发生错误！请检查文件内容与格式！');
            });
    }
</script>
</html>